/**
 * Created by hjy on 2017/9/19.
 */

var Index = require('../app/controllers/index');
var User = require('../app/controllers/user');
var Movie = require('../app/controllers/movie');
var Comment = require('../app/controllers/comment');
var Catetory = require('../app/controllers/catetory');

module.exports = function (app) {
    /**
     * 预处理
     */
    app.use(function (req,res,next) {
        // 把session放到页面上
        var _user = req.session.user;
        app.locals.user = _user;
        next()
    })
    // =================================== 首页模块 ===============================
    //首页
    app.get('/',Index.index);
    // =================================== 用户模块 ===============================
    app.post('/user/signup',User.signup); //注册
    app.post('/user/signin',User.signin);//登录
    app.get('/signin',User.showSignin);//登录页面
    app.get('/signup',User.showSignup);//注册页面
    app.get('/logout',User.logout);//退出
    app.get('/admin/user/list',User.signinRequired,User.adminRequired,User.list);//用户列表页
    // =================================== 电影模块 ===============================
    app.get('/movie/:id',Movie.detail);//访问电影详情页

    app.get('/admin/movie/update/:id',User.signinRequired,User.adminRequired,Movie.update);//修改电影信息
    app.get('/admin/movie/list',User.signinRequired,User.adminRequired,Movie.list);//访问列表页
    app.delete('/admin/movie/list',User.signinRequired,User.adminRequired,Movie.del);//删除

    app.get('/admin/movie/new',User.signinRequired,User.adminRequired,Movie.new); //录入电影信息
    app.post('/admin/movie',User.signinRequired,User.adminRequired,Movie.savePoster,Movie.save);//电影数据的存储
    // =================================== 评论 ===============================
    app.post('/user/comment',User.signinRequired,Comment.save);

    // =================================== 分类 ===============================
    app.get('/admin/catetory/new',User.signinRequired,User.adminRequired,Catetory.new);//后台分类录入页
    app.post('/admin/catetory',User.signinRequired,User.adminRequired,Catetory.save);//分类保存
    app.get('/admin/catetory/list',User.signinRequired,User.adminRequired,Catetory.list);//分类列表页


    // ===================================  ===============================
    app.get('/results',Index.search);//显示分类的所有信息
};
